<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2020/7/15
  Time: 18:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String basePath = request.getScheme()
            +"://"
            +request.getServerName()
            + ":"
            +request.getServerPort()
            +request.getContextPath()
            +"/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>注册</title>
    <script type="text/javascript">
        $(function(){
            $("#sub_btn").click(function () {
                var emailText=$("#email").val();
                var emailPatt=/^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/;
                if(!emailPatt.test(emailText)){
                    $("span.errorMsg").text("邮箱格式不合法!");
                    return false;
                }
                var creditText=$("#credit").val();
                var creditPatt=/^\d{15}|\d{}18$/;
                if(!creditPatt.test(creditText)) {
                    $("span.errorMsg").text("身份证号码必须为15位或18位数字!");
                    return false;
                }
                var usernameText=$("#username").val();
                var usernamePatt=/^[a-zA-Z]\w{5,9}$/;
                if(!usernamePatt.test(usernameText)){
                    $("span.errorMsg").text("用户名必须以字母开头，只能包括字母、下划线、数字，且长度必须在6到10之间!");
                    return false;
                }
                var codeText=$("#code").val();
                var codePatt=/^\d{4}$/;
                if(!codePatt.test(codeText)) {
                    $("span.errorMsg").text("验证码必须是数字, 并且是4位数字!");
                    return false;
                }
                var phoneText=$("#phone").val();
                var phonePatt=/1\d{10}/;
                if(!phonePatt.test(phoneText)){
                    $("span.errorMsg").text("手机号码格式不合法!");
                    return false;
                }
                $("span.errorMsg").text("");
            });
        });
    </script>
</head>
<body>
<h1>注册新用户</h1>
<span class="errorMsg">
</span>
<div class="form">
<form action="userServlet" method="post">
    <input type="hidden" name="action" value="regist" />
    <table>
        <tr>
    <td>用户名：</td>
    <td>
        <input type="text" placeholder="请输入用户名" tabindex="1" name="username" id="username"
               value="${requestScope.username}"/>
    </td>
        </tr>
        <tr>
    <td>电子邮箱：</td>
    <td>
        <input type="text" placeholder="请输入邮箱地址" tabindex="1" name="email" id="email"/>

    </td>
        </tr>
        <tr>
            <td>身份证：</td>
            <td>
                <input type="text" placeholder="请输入身份证" tabindex="1" name="email" id="credit"/>

            </td>
        </tr>
        <tr>
    <td>验证码：</td>
            <td>
                <input type="text" tabindex="1" name="code">
            </td>
        </tr>
        <tr>
    <td>
        <input type="submit" value="注册" id="sub_btn"/>
    </td>
        </tr>
    </table>
</form>
</div>
</body>
</html>
